﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pretext.Formatters {
	
	public class WhitespaceRemoverFormatter : IFormatter {

		public bool RemoveTabs { get; set; }
		public bool RemoveLinefeeds { get; set; }
		public bool IncludeEscapedCharacters { get; set; }

		public WhitespaceRemoverFormatter() {
			RemoveTabs = true;
			RemoveLinefeeds = true;
			IncludeEscapedCharacters = true;
		}

		public string Format(string s) {

			if (RemoveTabs) {
				s = s.Replace("\t", string.Empty);
				if (IncludeEscapedCharacters) {
					s = s.Replace(@"\t", string.Empty);
				}
			}

			if (RemoveLinefeeds) {
				s = s.Replace("\r", string.Empty);
				s = s.Replace("\n", string.Empty);

				if (IncludeEscapedCharacters) {
					s = s.Replace(@"\r", string.Empty);
					s = s.Replace(@"\n", string.Empty);
				}

			}

			return s;

		}

	}

}